home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-04-20 | 664 b | 32 lines |
- class Ex1204b {
- public static void main(String[] args) {
- MyThread t1 = new MyThread(1);
- MyThread t2 = new MyThread(2);
-
- t1.setPriority(Thread.MAX_PRIORITY);
- t2.setPriority(Thread.MIN_PRIORITY);
-
- t1.start();
- t2.start();
- }
- }
-
- class MyThread extends Thread {
- int id;
- MyThread(int id) {
- this.id = id;
- }
-
- public void run() {
- for (int i = 0; i < 100; i++) {
- if (id == 1 && i == 50) {
- try {
- sleep(1000);
- } catch (InterruptedException x) {
- }
- }
- System.out.println("My id is " + id);
- }
- }
- }
-